package com.coreservlets.jsf.ss11;

import java.io.Serializable;
import java.util.Locale;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;

@ManagedBean
@SessionScoped
public class FormSettings implements Serializable 
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private boolean isNormalSize = true;
	private boolean isEnglish = true;
	private final Locale ENGLISH = Locale.ENGLISH;
	private final Locale SPANISH = new Locale( "es");
	
	private boolean isBlack = true;
	
	
	public String getBodyStyleClass()
	{
		if( isNormalSize )
		{
			return( "normalSize");
		}
		else
		{
			return( "largeSize");
		}
	}
	
	public void setBlackColor( ActionEvent event )
	{
		isBlack = !isBlack;
	}
	
	public void setWhiteColor( ActionEvent event )
	{
		isBlack = false;
	}
	
	
	public String getBodyColorStyle()
	{
		if( isBlack )
		{
			return( "style1" );
		}
		else
		{
			return( "style2" );
		}
	}
	
	public void setNormalSize( ActionEvent event )
	{
		isNormalSize = true;
	}
	
	public void setLargeSize( ActionEvent event )
	{
		isNormalSize = false;
	}
	
	public void swapLocale1( ActionEvent event )
	{
		switchLocale();
	}
	
	private void switchLocale()
	{
		isEnglish = !isEnglish;
		Locale newLocale;
		
		if( isEnglish )
		{
			newLocale = ENGLISH;
		}
		else
		{
			newLocale = SPANISH;
		}
		
		FacesContext.getCurrentInstance().getViewRoot().setLocale( newLocale );
	}
	
	public Locale getLocale()
	{
		if( isEnglish )
		{
			return( ENGLISH );
		}
		else
		{
			return( SPANISH );
		}
	}
	
	public void swapLocale2( ValueChangeEvent event )
	{
		Boolean flag = (Boolean) event.getNewValue();
		
		if( flag )
		{
			switchLocale();
		}
	}
	
	public void swapColor( ValueChangeEvent event )
	{
		isBlack = !isBlack;
	}
	
	public boolean isChecked()
	{
		return( false );
	}
	
	public void setChecked( boolean flag )
	{
	}
}
